Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
The tsconfck package is a utility for TypeScript configuration management. It helps in resolving and loading TypeScript configuration files (tsconfig.json) by handling inheritance and references within these configurations. This is particularly useful in complex projects where tsconfig settings are split across multiple files or extended from other configurations.
Load and resolve tsconfig.json
This feature allows loading a tsconfig.json file, resolving all its extends and references to provide a final resolved configuration object. It handles the asynchronous nature of file reading and parsing, providing a promise-based API.
const { loadTsconfig } = require('tsconfck');
loadTsconfig('path/to/tsconfig.json').then(tsconfig => {
console.log(tsconfig);
}).catch(error => {
console.error(error);
});
tsconfig-paths is a package that helps in resolving and loading paths from tsconfig.json files for module resolution. Unlike tsconfck, which focuses more broadly on configuration loading and resolution, tsconfig-paths specifically targets path resolution to aid in module loading in non-TypeScript environments.
tsconfig-loader provides functionality to load tsconfig.json files without resolving the entire configuration. It's simpler than tsconfck as it does not handle the resolution of 'extends' or other complex configurations, focusing instead on direct loading of configurations as they are defined.
A utility to find and parse tsconfig files without depending on typescript
Because no simple official api exists and tsconfig.json isn't actual json.
npm install --save-dev tsconfck # or pnpm, yarn
import { parse } from 'tsconfck';
const {
tsconfigFile, // full path to found tsconfig
tsconfig, // tsconfig object including merged values from extended configs
extended, // separate unmerged results of all tsconfig files that contributed to tsconfig
solution, // solution result if tsconfig is part of a solution
referenced // referenced tsconfig results if tsconfig is a solution
} = await parse('foo/bar.ts');
import { parseNative } from 'tsconfck';
const {
tsconfigFile, // full path to found tsconfig
tsconfig, // tsconfig object including merged values from extended configs, normalized
result, // output of ts.parseJsonConfigFileContent
solution, // solution result if tsconfig is part of a solution
referenced // referenced tsconfig results if tsconfig is a solution
} = await parseNative('foo/bar.ts');
see API-DOCS
You can use a map to cache results and avoid reparsing if you process multiple ts files that share few tsconfig files
import { parse } from 'tsconfck';
// 1. create cache instance
const cache = new Map();
// 2. pass cache instance in options
const fooResult = await parse('src/foo.ts', { cache });
// 3. profit (if they share the same tsconfig.json, it is not parsed again)
const barResult = await parse('src/bar.ts', { cache });
You are responsible for clearing the cache if tsconfig files change on disk during its lifetime.
Always clear the whole cache if anything changes as objects in the cache can ref each other
Returned results are direct cache objects.
If you want to modify them, deep-clone first.
You can specify a root directory and provide a set of known tsconfig locations to improve performance in large projects
import { parse, findAll } from 'tsconfck';
const root = '.';
const tsConfigPaths = new Set([
...(await findAll(root, { skip: (dir) => dir === 'node_modules' || dir === '.git' }))
]);
const cache = new Map();
const parseOptions = { cache, root, tsConfigPaths };
// these calls use minimal fs
const fooResult = await parse('src/foo.ts', parseOptions);
const barResult = await parse('src/bar.ts', parseOptions);
Using the root option can lead to errors if there is no tsconfig inside root.
You are responsible for updating tsConfigPaths if tsconfig files are added/removed on disk during its lifetime.
find and parse reject for all errors they encounter.
For parse, you can choose to resolve with an empty result instead if no tsconfig file was found
import { parse } from 'tsconfck';
const result = await parse('some/path/without/tsconfig/foo.ts', {
resolveWithEmptyIfConfigNotFound: true
});
// result = { tsconfigFile: 'no_tsconfig_file_found',tsconfig: {} }
import type { TSConfig } from 'pkg-types';
Check out https://github.com/unjs/pkg-types
A simple cli wrapper is included, you can use it like this
# prints /path/to/tsconfig.json on stdout
tsconfck find src/index.ts
# prints all tsconfig.json in dir on stdout
tsconfck find-all src/
# print content of ParseResult.tsconfig on stdout
tsconfck parse src/index.ts
# print to file
tsconfck parse src/index.ts > output.json
# print content of ParseResult on stdout
tsconfck parse-result src/index.ts
# print to file
tsconfck parse-result src/index.ts > output.json
# print usage
tsconfck -h # or --help, -?, help
This repo uses
In addition to default commit-msg prefixes you can use 'wip: ' for commit messages in branches. PRs are going to be squash-merged
# install dependencies
pnpm install
# run tests
pnpm test
#run tests in watch mode (doesn't require dev in parallel)
pnpm test:watch
FAQs
A utility to work with tsconfig.json without typescript
The npm package tsconfck receives a total of 1,758,605 weekly downloads. As such, tsconfck popularity was classified as popular.
We found that tsconfck demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.